class ProfileController < ApplicationController
  def index
    @user = User.find(current_user.id)
  end

  def update
    @user = User.find(current_user.id)
    @user.update_attributes(params[:user])
    @user.save
    flash[:notice]="Profile was updated successfully"
    render "index"
  end
  def info
    @auctions=Auction.where(["user_id = #{current_user.id}"])
    @my_products=Product.where(["user_id = #{current_user.id} AND sold_out = 1"])
    @win_products=Product.where(["user_winner_id= #{current_user.id} AND sold_out = 1"])
    @total_win=0
    @total_my=0
    if @my_products != nil
      @my_products.each do |product|
        if product.auctings.last
          @total_my+=product.auctings.last.price
        end
      end
    end
    if @win_products!= nil
      @win_products.each { |product| @total_win+=product.auctings.last.price }
    end
  end

end
